package com.flyox.game.militarychess.bean;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OptionalDataException;
import java.io.Serializable;

import com.flyox.game.militarychess.bean.ChessSeat.SEAT_NAME;

public class ChessMan implements Serializable, Cloneable {

	private static final long serialVersionUID = -6725645971876814153L;
	public enum SHOWLEVEL{NONE,PERSONAL,TEAM,DESK,ALL};//旁观者未考虑
	// empty 表示没有棋子 unknow 有子但不知道是啥
	public enum NAME {
		EMPTY, UNKNOW, JUNQI, GONGBING, PAIZHANG, LIANZHANG, YINGZHANG, TUANZHANG, LVZHANG, SHIZHANG, JUNZHANG, SILING, DILEI, ZHANGDAN
	};

	private NAME name;
	private SEAT_NAME team;
	private Position position;// 棋子在布局中的坐标
	private SHOWLEVEL showLevel=SHOWLEVEL.PERSONAL;//棋子的可见级别
	
	public ChessMan(NAME name, SEAT_NAME team, Position position) {
		this.name = name;
		this.team = team;
		this.position = position;
	}

	public NAME getName() {
		return name;
	}

	public void setName(NAME name) {
		this.name = name;
	}

	public SEAT_NAME getTeam() {
		return team;
	}

	public void setTeam(SEAT_NAME team) {
		this.team = team;
	}

	public Position getPosition() {
		return position;
	}

	public void setPosition(Position position) {
		this.position = position;
	}
	public ChessMan clone(){
		ChessMan cm=new ChessMan(name,team,position.clone());
		cm.setShowLevel(showLevel);
		return cm;
	}
	public ChessMan deepClone() throws IOException, OptionalDataException, ClassNotFoundException {
		// write to stream
		ByteArrayOutputStream bo = new ByteArrayOutputStream();
		ObjectOutputStream oo = new ObjectOutputStream(bo);
		oo.writeObject(this);

		// read from stream
		ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
		ObjectInputStream oi = new ObjectInputStream(bi);

		return (ChessMan)(oi.readObject());
	}

	public SHOWLEVEL getShowLevel() {
		return showLevel;
	}

	public void setShowLevel(SHOWLEVEL showLevel) {
		this.showLevel = showLevel;
	}
	
	public String toString(){
		return "name="+name+" team="+team.name()+" showLevel="+showLevel.name()+" "+position.toString();
	}
}
